package com.kobeliu.entity;

/**
 * leetcode 704
 *
 * 简单的二分查找
 *
 * 题目太难了 先基础吧 人麻了
 *
 */

public class Demo_25_No704 {

    public static void main(String[] args) {
        int[] nums = {-1,0,1};
        System.out.println(search(nums,-1));
    }

    public static int search(int[] nums, int target) {
        int L = 0;
        int R = nums.length-1;
        while(L<=R){
            int mid = L + ((R-L)>>1);
            if(nums[mid]<target) L = mid+1;
            else if(nums[mid]>target) R = mid-1;
            else return mid;
        }
        return -1;
    }
}
